/*
 * GuiDisplayCreateGroupAccess.java
 *
 * Created on 27 July 2004, 04:51
 * Copyright (C) 2004, Velocityme Partnership
 */

package com.velocityme.client.gui.access;

import com.velocityme.client.gui.exception.ExceptionWindow;
import javax.ejb.*;
import java.util.*;
import com.velocityme.interfaces.*;
import com.velocityme.valueobjects.*;
import com.velocityme.client.utility.*;
import java.awt.Component;
import java.rmi.RemoteException;
import javax.naming.NamingException;
import javax.swing.JTabbedPane;
import com.velocityme.client.gui.exception.*;

/**
 *
 * @author  Robert Crida Work
 */
public class GuiDisplayCreateGroupAccess extends javax.swing.JPanel {
    
    private NodePK m_nodePK;
    private KeySession m_key;
    
    /** Creates new form GuiDisplayCreateGroupAccess */
    public GuiDisplayCreateGroupAccess(KeySession p_key, NodePK p_nodePK) {
        initComponents();
        m_key = p_key;
        m_nodePK = p_nodePK;
        try {
            jTextFieldNode.setText(StatelessRemoteClientSessionUtil.getSession().getNodePathName(m_key, m_nodePK));
            Collection groups = StatelessRemoteClientSessionUtil.getSession().getAllGroupValues(m_key);
            Iterator i = groups.iterator();
            while(i.hasNext()) {
                jComboBoxGroup.addItem(new GroupValueToString((GroupValue)i.next()));
            }
            RoleValue[] roles = StatelessRemoteClientSessionUtil.getSession().getAllRoleValues(m_key);
            for (int j = 0; j < roles.length; j++)
                jComboBoxRole.addItem(new RoleValueToString(roles[j]));
        }
        catch(Exception e) {
            ExceptionWindow.showError(e);
        }
    }
    
    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    private void initComponents() {//GEN-BEGIN:initComponents
        java.awt.GridBagConstraints gridBagConstraints;

        jPanel2 = new javax.swing.JPanel();
        jButtonOK = new javax.swing.JButton();
        jButtonCancel = new javax.swing.JButton();
        jPanel1 = new javax.swing.JPanel();
        jLabelNode = new javax.swing.JLabel();
        jTextFieldNode = new javax.swing.JTextField();
        jLabelGroup = new javax.swing.JLabel();
        jComboBoxGroup = new javax.swing.JComboBox();
        jLabelRole = new javax.swing.JLabel();
        jComboBoxRole = new javax.swing.JComboBox();

        setLayout(new java.awt.BorderLayout());

        jPanel2.setLayout(new java.awt.GridLayout(1, 0));

        jButtonOK.setText("OK");
        jButtonOK.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonOKActionPerformed(evt);
            }
        });

        jPanel2.add(jButtonOK);

        jButtonCancel.setText("Cancel");
        jButtonCancel.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonCancelActionPerformed(evt);
            }
        });

        jPanel2.add(jButtonCancel);

        add(jPanel2, java.awt.BorderLayout.SOUTH);

        jPanel1.setLayout(new java.awt.GridBagLayout());

        jPanel1.setMinimumSize(new java.awt.Dimension(0, 0));
        jLabelNode.setText("Node:");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.EAST;
        gridBagConstraints.insets = new java.awt.Insets(2, 2, 2, 2);
        jPanel1.add(jLabelNode, gridBagConstraints);

        jTextFieldNode.setEditable(false);
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 1;
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
        gridBagConstraints.weightx = 1.0;
        gridBagConstraints.insets = new java.awt.Insets(2, 2, 2, 2);
        jPanel1.add(jTextFieldNode, gridBagConstraints);

        jLabelGroup.setText("Group:");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.EAST;
        gridBagConstraints.insets = new java.awt.Insets(2, 2, 2, 2);
        jPanel1.add(jLabelGroup, gridBagConstraints);

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 1;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
        gridBagConstraints.insets = new java.awt.Insets(2, 2, 2, 2);
        jPanel1.add(jComboBoxGroup, gridBagConstraints);

        jLabelRole.setText("Role:");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.EAST;
        gridBagConstraints.insets = new java.awt.Insets(2, 2, 2, 2);
        jPanel1.add(jLabelRole, gridBagConstraints);

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 1;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
        gridBagConstraints.insets = new java.awt.Insets(2, 2, 2, 2);
        jPanel1.add(jComboBoxRole, gridBagConstraints);

        add(jPanel1, java.awt.BorderLayout.NORTH);

    }//GEN-END:initComponents

    private void jButtonCancelActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonCancelActionPerformed
        // Add your handling code here:
        getParent().remove(this);                        
    }//GEN-LAST:event_jButtonCancelActionPerformed

    private void jButtonOKActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonOKActionPerformed
        // Add your handling code here:
        GroupPK groupPK = ((GroupValue)jComboBoxGroup.getSelectedItem()).getPrimaryKey();
        RolePK rolePK = ((RoleValue)jComboBoxRole.getSelectedItem()).getPrimaryKey();
        try {
            StatelessRemoteClientSessionUtil.getSession().groupAccessCreate(m_key, m_nodePK, groupPK, rolePK);
            getParent().remove(this);
        }
        catch(Exception e) {
            ExceptionWindow.showError(e);
        }
    }//GEN-LAST:event_jButtonOKActionPerformed
    
    
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButtonCancel;
    private javax.swing.JButton jButtonOK;
    private javax.swing.JComboBox jComboBoxGroup;
    private javax.swing.JComboBox jComboBoxRole;
    private javax.swing.JLabel jLabelGroup;
    private javax.swing.JLabel jLabelNode;
    private javax.swing.JLabel jLabelRole;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JTextField jTextFieldNode;
    // End of variables declaration//GEN-END:variables
    
}
